<template>
    <el-dialog
            :title="!dataForm.id ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="底稿唯一标识" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="底稿唯一标识"></el-input>
                </el-form-item>
                <el-form-item label="使用的底稿模板ID" prop="templateId">
                        <el-input v-model.number="dataForm.templateId" placeholder="使用的底稿模板ID"></el-input>
                </el-form-item>
                <el-form-item label="所属审计项目ID" prop="auditProjectId">
                        <el-input v-model.number="dataForm.auditProjectId" placeholder="所属审计项目ID"></el-input>
                </el-form-item>
                <el-form-item label="审计程序" prop="auditProgram">
                        <el-input v-model="dataForm.auditProgram" placeholder="审计程序"></el-input>
                </el-form-item>
                <el-form-item label="创建时间" prop="createdAt">
                        <el-date-picker
                                v-model="dataForm.createdAt"
                                type="datetime"
                                placeholder="创建时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="更新时间" prop="updatedAt">
                        <el-date-picker
                                v-model="dataForm.updatedAt"
                                type="datetime"
                                placeholder="更新时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="底稿状态（如Draft、Reviewed、Approved）" prop="status">
                        <el-input v-model="dataForm.status" placeholder="底稿状态（如Draft、Reviewed、Approved）"></el-input>
                </el-form-item>
                <el-form-item label="审核人ID" prop="reviewerId">
                        <el-input v-model.number="dataForm.reviewerId" placeholder="审核人ID"></el-input>
                </el-form-item>
                <el-form-item label="审批人ID" prop="approverId">
                        <el-input v-model.number="dataForm.approverId" placeholder="审批人ID"></el-input>
                </el-form-item>
                <el-form-item label="审计程序执行过程" prop="executionDetails">
                        <el-input v-model="dataForm.executionDetails" placeholder="审计程序执行过程"></el-input>
                </el-form-item>
                <el-form-item label="审计发现的问题" prop="auditFindings">
                        <el-input v-model="dataForm.auditFindings" placeholder="审计发现的问题"></el-input>
                </el-form-item>
                <el-form-item label="获取的审计证据" prop="auditEvidence">
                        <el-input v-model="dataForm.auditEvidence" placeholder="获取的审计证据"></el-input>
                </el-form-item>
                <el-form-item label="审核意见" prop="reviewComments">
                        <el-input v-model="dataForm.reviewComments" placeholder="审核意见"></el-input>
                </el-form-item>
                <el-form-item label="审批意见" prop="approvalComments">
                        <el-input v-model="dataForm.approvalComments" placeholder="审批意见"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            id: null,
            templateId: null,
            auditProjectId: null,
            auditProgram: null,
            createdAt: null,
            updatedAt: null,
            status: null,
            reviewerId: null,
            approverId: null,
            executionDetails: null,
            auditFindings: null,
            auditEvidence: null,
            reviewComments: null,
            approvalComments: null
          },
          dataRule: {
            id: [
                        { required: true, message: '底稿唯一标识不能为空', trigger: 'blur' }
            ],
            templateId: [
                        { required: true, message: '使用的底稿模板ID不能为空', trigger: 'blur' }
            ],
            auditProjectId: [
                        { required: true, message: '所属审计项目ID不能为空', trigger: 'blur' }
            ],
            auditProgram: [
                        { required: true, message: '审计程序不能为空', trigger: 'blur' }
            ],
            createdAt: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
            ],
            updatedAt: [
                        { required: true, message: '更新时间不能为空', trigger: 'blur' }
            ],
            status: [
                        { required: true, message: '底稿状态（如Draft、Reviewed、Approved）不能为空', trigger: 'blur' }
            ],
            reviewerId: [
                        { required: true, message: '审核人ID不能为空', trigger: 'blur' }
            ],
            approverId: [
                        { required: true, message: '审批人ID不能为空', trigger: 'blur' }
            ],
            executionDetails: [
                        { required: true, message: '审计程序执行过程不能为空', trigger: 'blur' }
            ],
            auditFindings: [
                        { required: true, message: '审计发现的问题不能为空', trigger: 'blur' }
            ],
            auditEvidence: [
                        { required: true, message: '获取的审计证据不能为空', trigger: 'blur' }
            ],
            reviewComments: [
                        { required: true, message: '审核意见不能为空', trigger: 'blur' }
            ],
            approvalComments: [
                        { required: true, message: '审批意见不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.id = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.id = id || 0
            if (this.dataForm.id) {
              this.$http({
                url: this.$http.adornUrl(`/app/audit_working_paper/info/${this.dataForm.id}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appauditworkingpaper
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/audit_working_paper/${!this.dataForm.id ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>